package traveldream.ejb.entities;



import java.io.Serializable;
import java.lang.String;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;

import javax.persistence.*;
import javax.xml.bind.DatatypeConverter;

import traveldream.ejb.DTO.*;

/**
 * Entity implementation class for Entity: User
 *
 */
@Entity
@Table(name="USERS")
@NamedQuery(name = "user.findAll", query="SELECT g FROM User g")

public class User implements Serializable {

	@Id
	private String idUser;
	private String password;
	private String Phone;
	private String Address;
	private String Surname;
	private String Name;
	private static final long serialVersionUID = 1L;
	
	@ElementCollection(targetClass = Group.class)
    @CollectionTable(name = "user_group",
            joinColumns = @JoinColumn(name = "iduser"))
    @Enumerated(EnumType.STRING)
    @Column(name="idgroup")
    private List<Group> groups;
	
	@ManyToMany(mappedBy="buyers")
	private List<DefaultPackage> packages;
	
	@OneToMany(mappedBy="email_Customer")
	private List<CustomizedPackage> packagesC;
	
	@OneToMany(mappedBy="Email_Customer")
	private List<GiftList> giftListOwned;
	
	@OneToMany(mappedBy="buyer_Excursion")
	private List<GiftList> giftedExcursion;
	
	@OneToMany(mappedBy="buyer_Hotel")
	private List<GiftList> giftedHotel;
	
	@OneToMany(mappedBy="buyer_Going")
	private List<GiftList> giftedGoing;
	
	@OneToMany(mappedBy="buyer_Return")
	private List<GiftList> giftedReturn;

	


	public User() {
		super();
	}   
	
	public User(RegistrationDTO reDTO){
		super();
		MessageDigest messageDigest;
		try {
			messageDigest = MessageDigest.getInstance("SHA-256");
			byte[] digest = messageDigest.digest(reDTO.getPassword().getBytes());
			this.password = DatatypeConverter.printHexBinary(digest);
			this.idUser = reDTO.getIdUser();
			this.Address = reDTO.getAddress();
			this.Name = reDTO.getName();
			this.Surname = reDTO.getSurName();
			this.Phone = reDTO.getPhone();
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	
	
	public List<GiftList> getGiftListOwned() {
		return giftListOwned;
	}

	public void setGiftListOwned(List<GiftList> giftListOwned) {
		this.giftListOwned = giftListOwned;
	}

	public List<GiftList> getGiftedExcursion() {
		return giftedExcursion;
	}

	public void setGiftedExcursion(List<GiftList> giftedExcursion) {
		this.giftedExcursion = giftedExcursion;
	}

	public List<GiftList> getGiftedHotel() {
		return giftedHotel;
	}

	public void setGiftedHotel(List<GiftList> giftedHotel) {
		this.giftedHotel = giftedHotel;
	}

	public List<GiftList> getGiftedGoing() {
		return giftedGoing;
	}

	public void setGiftedGoing(List<GiftList> giftedGoing) {
		this.giftedGoing = giftedGoing;
	}

	public List<GiftList> getGiftedReturn() {
		return giftedReturn;
	}

	public void setGiftedReturn(List<GiftList> giftedReturn) {
		this.giftedReturn = giftedReturn;
	}

	public List<DefaultPackage> getPackages() {
		return packages;
	}

	public void setPackages(List<DefaultPackage> packages) {
		this.packages = packages;
	}
	
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
   
	public String getPhone(){
		return Phone;
	}
	
	public void setPhone(String Phone){
		this.Phone = Phone;
	}
	
	public String getAddress(){
		return Address;
	}
	
	public void setAddress(String Address){
		this.Address = Address;
	}
	
	public List<CustomizedPackage> getPackagesC() {
		return packagesC;
	}

	public void setPackagesC(List<CustomizedPackage> packagesC) {
		this.packagesC = packagesC;
	}

	public String getSurname(){
		return Surname;
	}
	
	public void setSurname(String Surname){
		this.Surname = Surname;
	}
	
	public String getName(){
		return Name;
	}
	
	public void setName(String Name){
		this.Name = Name;
	}

	public String getIdUser() {
		return idUser;
	}

	public void setIdUser(String idUser) {
		this.idUser = idUser;
	}

	public List<Group> getGroups() {
		return groups;
	}

	public void setGroups(List<Group> groups) {
		this.groups = groups;
	}
	
}

